package com.pdsu.graduation_design.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.CheckBox;
import android.widget.TextView;

import com.pdsu.graduation_design.R;
import com.pdsu.graduation_design.domain.UserAddress;

import java.util.List;

public class MyAddressListViewAdapter extends BaseAdapter {

    private Context context;


    private List<UserAddress> userAddresses;

    public MyAddressListViewAdapter(Context context, List<UserAddress> userAddresses) {
        this.context = context;
        this.userAddresses = userAddresses;
    }

    /**
     * 地址数据
     * @param context
     */
//    private
    public MyAddressListViewAdapter(Context context) {
        this.context = context;
    }

    @Override
    public int getCount() {
        return userAddresses.size();
    }

    @Override
    public Object getItem(int position) {
        return userAddresses.get(position);
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View view=View.inflate(context, R.layout.my_address_listview_item,null);
        TextView names= view.findViewById(R.id.my_address_lv_username_tv);
        names.setText(userAddresses.get(position).getUsername());
        CheckBox isDefault=view.findViewById(R.id.my_address_lv_isdefault_cb);
            isDefault.setChecked(userAddresses.get(position).isDefault());
        return view;
    }
}
